package ar.edu.utn.frba.tacs.warnes.utils;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class SessionWarnes {
	protected static SessionFactory sessionFactory;
	protected static Session session;
	
	public static Session crearSession() {
		//Buildea el sessionFactory
		if(sessionFactory == null)
			sessionFactory = new AnnotationConfiguration().
				configure().buildSessionFactory();
		// Abrimos session
		if(session == null || !session.isOpen())
			session = sessionFactory.openSession();
		return session;
	}

	public static void cerrarSession() {
		session.close();
		sessionFactory.close();
	}

	public static void matate() {
		session=null;
		sessionFactory=null;
	}
}
